DAY12:Complementary DNA


Posted by birdbirdmurmur on 2023-07-25

題目連結:

Complementary DNA

解法:

function DNAStrand(dna){
  return dna.replace(/[ACTG]/g, match =>{
    switch(match){
      case "A":
        return "T";
      case "T":
        return "A";
      case "C":
        return "G";
      case "G":
        return "C";
    }
  })
}

筆記:

替換字先想到replace()
/[ATCG]/g:找到所有A、T、C、G四個字母
switch()將傳遞進來的值通過case轉換成另外一個字


#javascript #Codewars #replace #switch







Related Posts

React hook form(4) - controlled component & forwardRef

React hook form(4) - controlled component & forwardRef

[AI] 深度學習模型 vs 傳統機器學習模型

[AI] 深度學習模型 vs 傳統機器學習模型

[ 紀錄 ] 實戰練習 - 留言版 (以 php 實作前端 + 後端)

[ 紀錄 ] 實戰練習 - 留言版 (以 php 實作前端 + 後端)


Comments